#e
#Title[铽uBw߁v]
#Text[]
#Image[]
#BackGround[]
#BGM[]
#PlayLevel[Extra]
#ScriptVersion[2]
#Player[FREE]


script_enemy_main
{
let wall=[];
let bossspd=0.3;
let usebomb=0;

	//GoɈxs镔
	@Initialize
	{
	//   eϐ

	//   XyJ[hf[^
	SetLife(1000);
	SetScore(100000);
	SetDamageRate(25,  0);
	SetTimer(80);
	SetInvincibility(250);
	LoadGraphic("script\img\ExRumia.png");
	CutIn(KOUMA,"铽uBw߁v",GetCurrentScriptDirectory~"..\img\cutin05.png",0,0,255,320);
	}
	//   ʒu܂ňړ
	SetMovePosition02(GetCenterX, GetCenterY-160, 60);

	BG_Standard;
	AtackTaskA;
	AtackTaskB;
	MoveTask;
	ControlTask;
	//G̃Ct0ɂȂ܂ŁA̕1t[1s
	@MainLoop
	{
		yield;


		if(OnBomb==false){
			SetCollisionA(GetX, GetY, 32);
			SetCollisionB(GetX, GetY, 24);
			usebomb=0;
		}
		else{
			usebomb++;
		}
		if(usebomb==1){
			BombBarrier;
		}
	}
	
	//`惋[vB1t[1s
	@DrawLoop
	{
		SetGraphicRect(0,1,63,64);
		if(GetSpeedX<0){
			SetGraphicRect(128,1,191,64);
		}
		if(GetSpeedX>0){
			SetGraphicRect(192,1,255,64);
		}
		SetColor(255,255,255);
		SetAlpha(255);
		if(OnBomb==true){SetAlpha(96);}
		SetTexture("script\img\ExRumia.png");//摜͔q
		DrawGraphic(GetX(),GetY());//G̍WEx[~A`;
	}
		
	//GłuԂɈxs镔
	@Finalize
	{
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back1.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back2.png");
	}
	//XyJ[h̔wi
	//Ă悢
	@BackGround
	{
		BG_Simple;
	}

	task AtackTaskA{
		wait(120);
		let ammo=4;
		let dir=0;
		loop(ammo){
			ShieldCannon(dir,100,1,50,GREEN03,60);
			ShieldCannon(dir,60,-1,30,GREEN03,60);
			dir+=360/ammo;
		}
	}

	task ShieldCannon(	//[U[
		dir,
		dismax,	//ŉ
		rot,
		interval,
		grf,
		delay
	){
		let obj=Obj_Create(OBJ_SHOT);
		let dis=0;
		let atackcount=0;
		wall=wall~[obj];
		Obj_SetPosition(obj,cos(dir)*dis+GetCenterX,sin(dir)*dis+GetCenterY);
		Obj_SetAngle(obj,dir);
		ObjShot_SetDelay(obj,delay);
		ObjShot_SetGraphic(obj,grf);
		ObjShot_SetBombResist(obj,true);
		wait(delay);

		while(!Obj_BeDeleted(obj)){
			Obj_SetPosition(obj,cos(dir)*dis+GetCenterX,sin(dir)*dis+GetCenterY);
			Obj_SetAngle(obj,dir);

			if(atackcount==interval){
				CreateLaser01(Obj_GetX(obj),Obj_GetY(obj),2,Obj_GetAngle(obj),60,10,BLUE01,0);
				atackcount=0;
			}
			atackcount++;
			dir+=rot;
			if(dis<dismax){dis++;}
			yield;

		}
	}

	task AtackTaskB{
		wait(120);
		let nway=64;
		while(true){
			let dir=rand(0,360);
			loop(nway){
				ConcealShot(GetX,GetY,4,dir,RED01,20);
				dir+=360/nway;
			}
			wait(15);
		}
	}
	task ConcealShot(	//ǂɎՂVbg
		x,
		y,
		spd,
		dir,
		grf,
		delay
	){
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,dir);
		Obj_SetSpeed(obj,spd);
		ObjShot_SetGraphic(obj,grf);
		ObjShot_SetDelay(obj,delay);
		while(!Obj_BeDeleted(obj)){
			let i=0;
			loop(length(wall)){
				if(Collision_Obj_Obj(wall[i],obj)==true){
					Obj_SetSpeed(obj,spd/10);
					ObjShot_FadeDelete(obj);
				}
				i++;
			}
			yield;
		}

	}

	task MoveTask{
		wait(240);
		while(true){
			SetX(cos(GetAngleToPlayer)*bossspd+GetX);
			SetY(sin(GetAngleToPlayer)*bossspd+GetY);
			yield;
		}
	}

	task ControlTask{
		wait(250);
		while(GetEnemyLife>500&&GetTimer>20){yield;}
		bossspd=0.5;
		while(GetTimer>20){yield;}
		bossspd=0.8;
	}

	#include_function".\function.txt"
}

